package com.cse.index;

import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;


import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;



import jeasy.analysis.MMAnalyzer;

public class WordAnalyzer {
	
	static Logger log = Logger.getLogger(WordAnalyzer.class);
	
	
	
	static Map<String,Analyzer> map = new HashMap<String,Analyzer>();
	//空白符分词
	static Analyzer white  = new WhitespaceAnalyzer();
	//中文分词
	static MMAnalyzer mm = new MMAnalyzer();
	
	
	/**
	 * 初始化map
	 */
	
	
	static{
		map.put("white", white);
		map.put("mm", mm);
	}
	
	
	
	

	public static void analyze(String type, String text) {
		Analyzer analyzer = map.get(type);
		try{
		if(analyzer == null){
			throw new ClassNotFoundException();
		}
		
		
        TokenStream tokenStream = analyzer.tokenStream("content",
                new StringReader(text));
        for (Token token = new Token(text, 0, 0); (token = tokenStream.next()) != null;) {
        	System.out.println(token.termText());
            
        }
		}catch(Exception e){
			System.out.println(e);
		}
    }
	
	
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		String test = "习近平表示，去年，我同奥巴马总统两次会晤，达成了一系列重要共识，推动中美关系进入构建新型大国关系新阶段。" +
		"中方愿同美方一道努力，坚持构建新型大国关系大方向，尊重和照顾彼此核心利益和重大关切，加强对话、互信、合作，" +
		"推动中美关系持续健康稳定发展。" +
		"我期待着不久后同奥巴马总统再次会晤，欢迎你的夫人米歇尔女士近期访华。";
		String next = "CONOR 酷诺 T900 移动3G（TD-SCDMA/GSM）双卡双待 手机 黑色 定制机";


		try{
			WordAnalyzer.analyze("mm", test);
		}catch(Exception e){
			System.out.println(e);
		}

	}

}
